package com.iwords.android;

import org.json.JSONArray;
import org.json.JSONException;

public class JSONUtils {
	public static JSONArray getArray(org.json.JSONObject value) throws JSONException {
		JSONArray result = new JSONArray();
		if(!value.has("nv") || !value.has("nk")) return null;
		JSONArray values = (JSONArray) value.get("nv");
		JSONArray keys = (JSONArray) value.get("nk");

		if (values == null || keys == null) {
			//System.out.println("JSONUtils.getArray() return null");
			return null;
		}

		for (int j = 0; j < values.length(); j++) {
			JSONArray array = (JSONArray) values.get(j);
			org.json.JSONObject o = new org.json.JSONObject();
			for (int i = 0; i < keys.length(); i++) {
				o.put((String) keys.get(i), array.get(i));

			}
			result.put(o);

		}
		return result;
	}
}
